home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Frameworks / Sprocket Framework DR2 / Sprocket Framework Interfaces / MenuBar.h < prev    next >
Encoding:
Text File  |  1996-05-31  |  3.8 KB  |  174 lines  |  [TEXT/CWIE]

  1. // Sprocket Framework header file
  2. // Menubar.h
  3.  
  4.  
  5. #ifndef    _MENUBAR_
  6. #define    _MENUBAR_
  7.  
  8. #include <Menus.h>
  9. #include "SortedDynamicArray.h"
  10.  
  11. //    bare types are dangerous, eh?
  12.  
  13. typedef    SInt16    MenuID;
  14. typedef    UInt16    MenuItemID;
  15. typedef    SInt16    MenuBarTemplateID;
  16. typedef    UInt32    CommandID;
  17.  
  18. //    Some types which should probably be defined in <Menus.h>
  19. //    NOTE: These must be aligned on 2-byte boundaries
  20. #if PRAGMA_ALIGN_SUPPORTED
  21. #pragma options align=mac68k
  22. #endif
  23.  
  24. //    Kinda strange that NONE of the toolbox headers define
  25. //    the ON-DISK representations of their template resources, eh?
  26.  
  27. typedef    struct    MenuBarResource    MenuBarResource;
  28.  
  29. struct    MenuBarResource
  30.     {
  31.     UInt16    numberOfMenus;
  32.     SInt16    menuIDList[1];
  33.     };
  34.  
  35.  
  36. //    CMNU Resources look just like 'MENU' resources, except that
  37. //    each item is appended with an extra (2-byte aligned) longword.
  38. //
  39. //    They are evil because menu items always start out screwed up
  40. //    because some bright individual decided to START the record
  41. //    with the variable-sized field!.
  42. //
  43. //    In the long run this is still OK, because ResEdit and Resourceror
  44. //    already create and edit CMNU resources. All the evil is confined
  45. //    within parts of Sprocket you don’t have to modify.
  46.  
  47. typedef    struct    CMNUResource    CMNUResource;
  48. typedef    struct    CMNUItemData    CMNUItemData;
  49.  
  50.  
  51. //    CW6 didn’t like having this below the CMNUResource definition,
  52. //    even though CW5 didn’t complain:
  53.  
  54. struct    CMNUItemData
  55.     {
  56.     Str255                itemString;    //    don’t you hate structures that start out misalinged!
  57.     Byte                itemIcon;
  58.     Byte                itemCmd;
  59.     Byte                itemMark;
  60.     Style                itemStyle;
  61.     CommandID        itemCommand;
  62.     };
  63.  
  64.  
  65. struct CMNUResource
  66.     {
  67.     short                menuID;
  68.     short                menuWidth;
  69.     short                menuHeight;
  70.     Handle                menuProc;
  71.     long                enableFlags;
  72.     Str255                menuTitle;
  73.     CMNUItemData        menuData[1];    //    here begins evil!
  74.     };
  75.  
  76.  
  77. //    Restore default alignment
  78. #if PRAGMA_ALIGN_SUPPORTED
  79. #pragma options align=reset
  80. #endif
  81.  
  82.  
  83. enum
  84.     {
  85.     kNoMenuID            =    0,
  86.     kNoMenuItemID        =    0,
  87.     kNoMenuCommandID    =    0
  88.     };
  89.  
  90.  
  91. struct    MenuMapping
  92.     {
  93.     MenuID            fMenu;
  94.     MenuItemID        fItem;
  95.     CommandID    fCommand;        //    the command ID, which must be unique
  96.     };
  97.  
  98.  
  99. class    TMenuItemTable : public TSortedDynamicArray
  100.     {
  101.     virtual    CompareResult    Compare(ArrayElementPtr element1,
  102.                                     ArrayElementPtr    element2);
  103.     };
  104.  
  105.  
  106. class    TMenuCommandTable : public TSortedDynamicArray
  107.     {
  108.     virtual    CompareResult    Compare(ArrayElementPtr element1,
  109.                                     ArrayElementPtr    element2);
  110.     };
  111.  
  112.  
  113. class    TMenuBar
  114.     {
  115. public:
  116.     //    Resource ('MBAR' and 'CMNU') Utilities
  117.     
  118.     OSErr                    GetNewMenuBar(short whichMBAR);
  119.     MenuRef                    GetMenuFromCMNU(short whichMenu);
  120.     
  121.     //    Menu command mapping functions
  122.  
  123.     CommandID            GetCommand(MenuID menu, MenuItemID item);
  124.     void                    GetMenuAndItem(CommandID commandNum, MenuID * returnedMenu, MenuItemID * returnedItem);
  125.     
  126.     OSErr                    RegisterCommand(CommandID commandNum, MenuID menu, MenuItemID item);
  127.     OSErr                    UnregisterCommand(CommandID commandNum);
  128.     
  129.     //    Menu enable/disable routines for menu items
  130.  
  131.     void                    EnableCommand(CommandID commandNum, Boolean enable);
  132.     void                    EnableAndCheckCommand(CommandID commandNum, Boolean enable, Boolean check);
  133.  
  134.     void                    GetItemString(CommandID commandNum, StringPtr itemString);
  135.     void                    SetItemString(CommandID commandNum, StringPtr itemString);
  136.     
  137.     void                    SetItemStyle(CommandID commandNum, Style aStyle);
  138.     
  139.     OSErr                    HiliteMenusForModalDialog(Boolean hiliting);
  140.  
  141.  
  142.     //    helpful utility functions
  143.  
  144.     void                    HideMenuBar();
  145.     void                    ShowMenuBar();
  146.  
  147.     void                    RedrawIfNeeded();
  148.     void                    Invalidate();
  149.     void                    Validate();    
  150.  
  151. private:
  152.     //    "globals"
  153.     
  154.     static Boolean            fgMenuBarNeedsRedraw;
  155.     static Boolean            fgMenuBarHidden;
  156.     static short            fgMenuBarHeight;
  157.     static RgnHandle        fgMenuBarRgn;
  158.     
  159.     //    private vars
  160.     
  161.     short                    fCurrentMBAR;
  162.  
  163.     //    mapping tables
  164.  
  165.     TMenuCommandTable        fCommandTable;
  166.     TMenuItemTable            fMenuItemTable;
  167.  
  168.     //    internal methods
  169.     
  170.     MenuRef                    GetMenuRefAndItemFromCommand(CommandID commandNum, MenuID *menu,MenuItemID *item);
  171.     };
  172.  
  173. #endif
  174.